package org.boulderfoodrescue.webapp.client.old.viewer;

import org.boulderfoodrescue.webapp.client.googlemap.GoogleMap;
import org.boulderfoodrescue.webapp.client.old.viewer.findaddress.FindAddressPanel;
import org.boulderfoodrescue.webapp.client.old.viewer.savepickup.SavePickupPanel;
import org.boulderfoodrescue.webapp.client.old.viewer.scheduler.SchedulerPanel;
import org.boulderfoodrescue.webapp.shared.Place;

import com.google.gwt.core.client.GWT;
import com.google.gwt.maps.client.geocode.Placemark;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.Widget;

public class SideBarPanel extends Composite{

  private static SideBarPanelUiBinder uiBinder = GWT
      .create(SideBarPanelUiBinder.class);

  interface SideBarPanelUiBinder extends UiBinder<Widget, SideBarPanel> {
  }

  public SideBarPanel(GoogleMap gMap, SideBar parent) {
    this.gMap = gMap;
    placesCellTable = new PlacesCellTable(gMap);
    initWidget(uiBinder.createAndBindUi(this));
    findAddressPanel = new FindAddressPanel(this);
    saveAddressPanel = new SavePickupPanel(this,gMap);
    schedulerPanel = new SchedulerPanel(this, gMap);
    operation_flowPanel.add(findAddressPanel);
//    operation_flowPanel.add(saveAddressPanel);
//    addressInfoEntered(new Place());
  }
 
  @UiField
  FlowPanel myLocationsPanel;
  @UiField
  FlowPanel operation_flowPanel;
  @UiField(provided = true)
  PlacesCellTable placesCellTable;
  protected SavePickupPanel saveAddressPanel;
  protected FindAddressPanel findAddressPanel;
  protected SchedulerPanel schedulerPanel;
  protected GoogleMap gMap;
  
  public void addressFound(Placemark location)
  {
    saveAddressPanel.onAddressFound(location);
    operation_flowPanel.remove(findAddressPanel);
    operation_flowPanel.add(saveAddressPanel);
  }
  public void addressInfoEntered(Place current) {
  	schedulerPanel.setPlace(current);
    operation_flowPanel.remove(saveAddressPanel);
    operation_flowPanel.add(schedulerPanel);
  }
  public void pickupSaved() {
    operation_flowPanel.remove(schedulerPanel);
    operation_flowPanel.add(findAddressPanel);
  }
  public void onCancelNewPickup()
  {
    operation_flowPanel.clear();
    operation_flowPanel.add(findAddressPanel);
  }
}

